package com.lxy.cxcyxmmsbackend.sys.res;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author lxy
 */
@Data
@NoArgsConstructor
@Repository
@ApiModel("返回结果类 code msg data")
public class Result<T> {
    @ApiModelProperty("状态码")
    private String code;
    @ApiModelProperty("信息")
    private String msg;
    @ApiModelProperty("数据")
    private T data;

    //只有数据
    public Result(T data) {
        this.data = data;
    }

    //状态码为200 msg 为成功 无数据
    public Result<T> success() {
        this.setCode("200");
        this.setMsg("成功");
        return this;
    }

    //状态码为202 msg 为失败 无数据
    public static Result error(String msg) {
        return new Result("202", msg);
    }

    //状态码为200 msg 为成功 携带数据
    public static <T> Result<T> success(String msg, T data) {
        return new Result<>("200", msg, data);
    }

    //全参
    public Result(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    //状态码和 msg
    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }


}
